Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test selection method #10102

Merged
merged 4 commits into from
May 8, 2024
Merged

Unit test selection method #10102

merged 4 commits into from
May 8, 2024

Conversation

MichelleArk
Copy link
Contributor

@MichelleArk MichelleArk commented May 7, 2024

resolves: #10053
resolves: #9895

Problem

unit tests could not be passed in using --select unit_test:*

Solution

implement unit test selection method!

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

Some additional 🎩

❯ dbt ls --resource-type unit_test
20:41:11  Running with dbt=1.9.0-a1
20:41:11  target not specified in profile 'postgres', using 'default'
20:41:11  Registered adapter: postgres=1.9.0-a1
20:41:12  Found 15 models, 6 seeds, 20 data tests, 6 sources, 13 metrics, 684 macros, 6 semantic models, 4 unit tests
unit_test:jaffle_shop.test_supply_costs_sum_correctly
unit_test:jaffle_shop.test_order_items_compute_to_bools_correctly
unit_test:jaffle_shop.test_recursive_cte
unit_test:jaffle_shop.test_does_location_opened_at_trunc_to_date

❯ dbt ls --select unit_test:jaffle_shop.test_recursive_cte
20:41:18  Running with dbt=1.9.0-a1
20:41:18  target not specified in profile 'postgres', using 'default'
20:41:19  Registered adapter: postgres=1.9.0-a1
20:41:19  Found 15 models, 6 seeds, 20 data tests, 6 sources, 13 metrics, 684 macros, 6 semantic models, 4 unit tests
unit_test:jaffle_shop.test_recursive_cte

❯ dbt test --select unit_test:jaffle_shop.test_recursive_cte
20:41:24  Running with dbt=1.9.0-a1
20:41:24  target not specified in profile 'postgres', using 'default'
20:41:25  Registered adapter: postgres=1.9.0-a1
20:41:25  Found 15 models, 6 seeds, 20 data tests, 6 sources, 13 metrics, 684 macros, 6 semantic models, 4 unit tests
20:41:25  
20:41:26  Concurrency: 1 threads (target='default')
20:41:26  
20:41:26  1 of 1 START unit_test recursive_cte::test_recursive_cte ....................... [RUN]
20:41:26  1 of 1 PASS recursive_cte::test_recursive_cte .................................. [PASS in 0.14s]
20:41:26  
20:41:26  Finished running 1 unit test in 0 hours 0 minutes and 1.27 seconds (1.27s).
20:41:27  
20:41:27  Completed successfully
20:41:27  
20:41:27  Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1

@cla-bot cla-bot bot added the cla:yes label May 7, 2024
Copy link

codecov bot commented May 7, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 88.21%. Comparing base (04ebe0f) to head (5ba1495).
Report is 2 commits behind head on main.

Files Patch % Lines
core/dbt/graph/selector_methods.py 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10102      +/-   ##
==========================================
+ Coverage   88.20%   88.21%   +0.01%     
==========================================
  Files         181      181              
  Lines       22749    22788      +39     
==========================================
+ Hits        20066    20103      +37     
- Misses       2683     2685       +2     
Flag Coverage Δ
integration 85.55% <17.64%> (-0.04%) ⬇️
unit 62.68% <88.23%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MichelleArk MichelleArk marked this pull request as ready for review May 7, 2024 20:43
@MichelleArk MichelleArk requested a review from a team as a code owner May 7, 2024 20:43
def test_select_unit_test(manifest: Manifest) -> None:
test_model = make_model("test", "my_model", "select 1 as id")
unit_test = make_unit_test("test", "my_unit_test", test_model)
manifest.unit_tests[unit_test.unique_id] = unit_test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you feel like this is easier to use or we somehow have a fixture called unittests that will be required by manifest and you return all unittest nodes in it easier? Or maybe not so much difference?
cc @QMalcolm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was very easy to use! and keeps unit tests more narrow and isolated from one another in their setup

Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the test_graph_selectore_methods.py should be moved to
tests/unit/graph/test_selector_methods.py, but I can do it in my big reorganizing everything issue

@MichelleArk
Copy link
Contributor Author

@ChenyuLInx -- I'll do the move here! Should be quick :)

@MichelleArk MichelleArk merged commit 43d6c2f into main May 8, 2024
63 checks passed
@MichelleArk MichelleArk deleted the unit-test-selection-method branch May 8, 2024 13:55
Copy link
Contributor

github-actions bot commented May 8, 2024

The backport to 1.8.latest failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.8.latest 1.8.latest
# Navigate to the new working tree
cd .worktrees/backport-1.8.latest
# Create a new branch
git switch --create backport-10102-to-1.8.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 43d6c2f369cff8ed888c44c677d0b3468a9186aa
# Push it to GitHub
git push --set-upstream origin backport-10102-to-1.8.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.8.latest

Then, create a pull request where the base branch is 1.8.latest and the compare/head branch is backport-10102-to-1.8.latest.

MichelleArk added a commit that referenced this pull request May 8, 2024
(cherry picked from commit 43d6c2f)
MichelleArk added a commit that referenced this pull request May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants